home *** CD-ROM | disk | FTP | other *** search
- unit Desktop;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
-
- type
- TDesktop = class (TCustomControl)
- private
- { Private declarations }
- fListView: hWnd;
- fFont: TFont;
- function GetItemCount: Integer;
- procedure SetItemCount (Value: Integer);
- procedure SetTextColor (Value: TColor);
- function GetTextColor: TColor;
- procedure SetTextBackgroundColor (Value: TColor);
- function GetTextBackgroundColor: TColor;
- procedure SetFont (Value: TFont);
- function GetFont: TFont;
- protected
- { Protected declarations }
- procedure Paint; override;
- public
- { Public declarations }
- constructor Create (AOwner: TComponent); override;
- destructor Destroy; override;
- published
- { Published declarations }
- property Font: TFont read GetFont write SetFont;
- property ItemCount: Integer read GetItemCount write SetItemCount;
- property TextColor: TColor read GetTextColor write SetTextColor;
- property TextBackgroundColor: TColor read GetTextBackgroundColor write SetTextBackgroundColor;
- end;
-
- procedure Register;
-
- implementation
-
- uses CommCtrl;
-
- constructor TDesktop.Create (AOwner: TComponent);
- begin
- Inherited Create (AOwner);
- Width := GetSystemMetrics (sm_CxIcon);
- Height := GetSystemMetrics (sm_CyIcon);
- Visible := False;
- fFont := TFont.Create;
- // Start with the desktop window
- fListView := GetDesktopWindow;
- // Search through desktop children for the shell
- fListView := FindWindowEx (fListView, 0, 'Progman', 'Program Manager');
- // Search shell's children for the shell default view
- fListView := FindWindowEx (fListView, 0, 'SHELLDLL_DefView', Nil);
- // Finally, get the listview that's inside the shell default view
- fListView := FindWindowEx (fListView, 0, 'SysListView32', Nil);
- end;
-
- destructor TDesktop.Destroy;
- begin
- fFont.Free;
- Inherited;
- end;
-
- procedure TDesktop.Paint;
- begin
- if csDesigning in ComponentState then
- DrawIcon (Canvas.Handle, 0, 0, LoadIcon (0, idi_WinLogo));
- end;
-
- function TDesktop.GetFont: TFont;
- begin
- Result := fFont;
- end;
-
- procedure TDesktop.SetFont (Value: TFont);
- begin
- fFont.Assign (Value);
- SendMessage (fListView, wm_SetFont, fFont.Handle, Integer (True));
- end;
-
- procedure TDesktop.SetTextColor (Value: TColor);
- begin
- Value := ColorToRGB (Value);
- if Value <> GetTextColor then begin
- ListView_SetTextColor (fListView, Value);
- InvalidateRect (fListView, Nil, True);
- end;
- end;
-
- function TDesktop.GetTextColor: TColor;
- begin
- Result := ListView_GetTextColor (fListView);
- end;
-
- procedure TDesktop.SetTextBackgroundColor (Value: TColor);
- begin
- // If wanted color is clNone, interpret as Transparent
- if Value = clNone then Value := $ffffffff else Value := ColorToRGB (Value);
- if Value <> GetTextBackgroundColor then begin
- ListView_SetTextBkColor (fListView, Value);
- InvalidateRect (fListView, Nil, True);
- end;
- end;
-
- function TDesktop.GetTextBackgroundColor: TColor;
- begin
- Result := ListView_GetTextBkColor (fListView);
- end;
-
- function TDesktop.GetItemCount: Integer;
- begin
- Result := ListView_GetItemCount (fListView);
- end;
-
- procedure TDesktop.SetItemCount (Value: Integer);
- begin
- // Read only property
- end;
-
- procedure Register;
- begin
- RegisterComponents ('Samples', [TDesktop]);
- end;
-
- end.
-